<!DOCTYPE html>
<html>
<head>
	<include file="Public:common-css" />
	<link type="text/css" rel="stylesheet" href="__ICSS__/login.css" />
</head>
<body>
<div class="container">
<!-------------------------header--------------------------------->
<include file="Public:header2" />
<!-------------------------header-end----------------------------->
<div class="clr"></div>
<!--------------------------content------------------------------->
	<div class="lr-box">
    	<div class="login-content">
        	<div class="login-ad"><img src="__IIMG__/login-ad.jpg"/></div>
        	<div class="login-wrap">
	            <div class="login">
                	<div class="login-t"><span>登录</span> | <a href="__ROOT__/Login/register">注册</a></div>
                    <p class="message" style="display:none"></p>
                    <div class="clr"></div>
                    <p class="check-success"><input type="text" class="l-input" id="userName" placeholder="请输入手机号码/用户名" name="username"/><span style="display:none;"><i class="check-error-icon"></i>请输入手机号或用户名</span><b class="user-name-icon"></b></p>
                    <div class="clr"></div>
                    <p class="check-success"><input type="password" class="l-input" id="loginPassword" placeholder="请输入密码" name="password"/><span style="display:none;"><i class="check-error-icon"></i>请输入密码</span><b class="password-icon"></b></p>
                    <p class="login-auto-checkbox"><label for="auto"><input type="checkbox" id="auto" checked="checked"/>&nbsp记住我的账号</label><a href="__ROOT__/Login/findPassword" class="gray7 right">忘记密码？</a></p>
                    <p><input type="button" id="btn" value="登 录" class="submit-btn msyh"/></p>
	            </div>
            </div>
        </div>
        <div class="clr"></div>
    </div>
<!--------------------------content-end--------------------------->
    <include file="Public:footer" />
</div>

</body>
<include file="Public:common-js" />
<script type="text/javascript">
//登录验证
$(function(){
	initAdSize();
	$(window).resize(function () {
		initAdSize();
	});
	window.onload = function(){
		initAdSize();
	}
	function initAdSize() {
		var width = $(".login-content").width() - $(".login-wrap").width();
		$(".login-ad").width(width);
		if($(".login-box").width() == 1200) {
			$(".login-ad").find("img").width(width * 0.7);
		}else if($(".login-box").width() == 980) {
			$(".login-ad").find("img").width(width * 0.9);
		}
		var loginWrapHeight = $(".login-wrap").height();
		var imgHeight = $(".login-ad").find("img").height();
		if(imgHeight < loginWrapHeight) {
			$(".login-ad").find("img").css("margin-top",(loginWrapHeight - imgHeight  - 90)/2);
		}else{
			$(".login-ad").find("img").css("margin-top",0);
		}
	}
	//初始化提示信息
	$("input").each(
		function() {
			if($(this).attr("original-title") != undefined){
				$(this).css("color","#888");
				$(this).val($(this).attr("original-title"));
			}
		}
	)
    
	var $userName = $("#userName");
	var $passWord = $("#loginPassword");
	var $input = $(".l-input");
	$input.focus(function(){
		$(this).parent().attr("class","check-success");
		$(this).next().hide();
		if($(this).val() == $(this).attr("original-title")){
			$(this).val("");
		}	
	});
	$userName.blur(function() {
		if($(this).val() == ""){
			$(this).val($(this).attr("original-title"));
		}
	});
	var COOKIE_NAME = 'loginName';  
    if( $.cookie(COOKIE_NAME) ){  
        $("#userName").val($.cookie(COOKIE_NAME) );  
    }  
    
	$("#btn").click(function(){
		$(".message").hide();
		var $temp = true;
		if($passWord.val() == ""){
			$passWord.parent().attr("class","check-error");
			$passWord.next().show();
			$temp = false;
		}
		if($userName.val() == "" || $userName.val() == $userName.attr("original-title")){
			$userName.parent().attr("class","check-error");
			$userName.next().show();
			$temp = false;
		}
		if($temp == false){
			return false;
		}else{
			$(this).val("登录中...");
			$(this).attr("disabled","true");
			$.ajax({
				url:'__URL__/login',
				type:'post',
				dataType:'json',
				data:{username:$("#userName").val(),password:$("#loginPassword").val()},
				success:function(json){
					if(json.status == 1){
						$(".message").html(json.data);
						if($("#auto").is(":checked")){  
				            $.cookie(COOKIE_NAME, $("#userName").val() , { path: '/', expires: 10 });  
				            //var date = new Date();  
				            //date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000)); //三天后的这个时候过期  
				            //$.cookie(COOKIE_NAME, $("#username").val(), { path: '/', expires: date });  
				        }else{  
				            $.cookie(COOKIE_NAME, null, { path: '/' });  //删除cookie  
				        }  

						var HREF_COOKIE = 'HREF_COOKIE';
						var cookieUnde = true;
						if( $.cookie(HREF_COOKIE) == undefined){
							cookieUnde = false;
						}else if($.cookie(HREF_COOKIE) == "null"){
							cookieUnde = false;
						}
						if(cookieUnde) {
							window.location.href = $.cookie(HREF_COOKIE);
						}else{
							window.location.href= "__ROOT__";
						}
						$.cookie(HREF_COOKIE, null, { path: '/' });
					}else{
						$passWord.val("");
						$(".message").html(json.info);
						$("#btn").val("登 录");
						$("#btn").removeAttr("disabled");
						$(".message").show();
					}
				},
				error:function(json){
					$passWord.val("");
					$(".message").html("登录错误");
					$("#btn").val("登 录");
					$("#btn").removeAttr("disabled");
					$(".message").show();
				}
			})
		}
	});
	//监听回车事件
	document.onkeydown = function(ev){
	  	ev = ev || window.event;
	  	if(ev.keyCode == 13){
	   		document.getElementById('btn').click();
	  	}
	 }
	 
})
</script>

</html>
